package edu.biwu.mapper;

import edu.biwu.po.Order;
import edu.biwu.po.User;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;

import java.util.List;

/**
 * @author 王俊彪
 * @version 1.0
 */
public interface OrderMapper {

    /**
     * 查询所有订单（按需加载订单关联的用户信息）
     * @return
     */
    @Results({
            @Result(column = "user_id",property = "userId"),
            @Result(property = "user",column = "user_id" ,javaType = User.class,
            one = @One(select = "edu.biwu.mapper.UserMapper.findById" , fetchType = FetchType.LAZY))
    })
    @Select(" SELECT * FROM mybatis03.`order`;")
    List<Order> findOrderAndUserLazy();

    /**
     * 查询所有订单（延迟加载订单关联的用户信息和订单关联的订单明细）
     * @return
     */
    @Results({
            @Result(column = "id",property = "id",id=true),
            @Result(column = "user_id",property = "userId"),
            @Result(property = "user",column = "user_id" ,javaType = User.class,
                    one = @One(select = "edu.biwu.mapper.UserMapper.findById" , fetchType = FetchType.LAZY)),
            @Result(property = "orderDetails" , javaType = List.class,column = "id",
                    many =@Many(select = "edu.biwu.mapper.OrderDetailMapper.findByOrderId",fetchType = FetchType.LAZY))
    })
    @Select("SELECT * FROM mybatis03.`order`")
    List<Order> findOrderAndOrderDetailLazy();


}
